home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / msflex1a / frmflexn.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-20  |  5.6 KB  |  169 lines

  1. VERSION 5.00
  2. Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
  3. Begin VB.Form frmFlexNavigate 
  4.    Caption         =   "Ascii Code Table"
  5.    ClientHeight    =   1635
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   3960
  9.    KeyPreview      =   -1  'True
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   1635
  12.    ScaleWidth      =   3960
  13.    StartUpPosition =   2  'CenterScreen
  14.    Begin VB.TextBox tabSimm 
  15.       Height          =   285
  16.       Left            =   120
  17.       TabIndex        =   1
  18.       Text            =   "Text1"
  19.       Top             =   1680
  20.       Width           =   855
  21.    End
  22.    Begin MSFlexGridLib.MSFlexGrid grd 
  23.       Height          =   1455
  24.       Left            =   120
  25.       TabIndex        =   0
  26.       Top             =   120
  27.       Width           =   3735
  28.       _ExtentX        =   6588
  29.       _ExtentY        =   2566
  30.       _Version        =   65541
  31.       FixedCols       =   0
  32.       FocusRect       =   2
  33.    End
  34. Attribute VB_Name = "frmFlexNavigate"
  35. Attribute VB_GlobalNameSpace = False
  36. Attribute VB_Creatable = False
  37. Attribute VB_PredeclaredId = True
  38. Attribute VB_Exposed = False
  39. Option Explicit
  40. 'Program Documentation:
  41. 'Written by: Daniel L. Botkin
  42. 'Date: September 16, 1999
  43. 'Written in: Visual Basic 5.0 (SP3)
  44. 'What It Does:
  45. '  Allows user to use the Tab and Shift Tab keys to
  46. '  Navigate between cells in MSFlexGrid.
  47. 'Purpose:
  48. '  This code was written to show a very simplictic way
  49. '  of using the tab key for navigation between cells
  50. '  in MSFlexGrid.  It was written to show the basic
  51. '  concept and nothing else.  Please remember that the
  52. '  more code you write to manipulate MSFlexGrid the
  53. '  more this code will have to be modified.
  54. 'Why:
  55. '  To this present date I have not been able to find a
  56. '  way to trap the tab key.  Since I use MSFlexGrid in
  57. '  alot of programs I write, I needed a way to navigate
  58. '  between cells in the grid with the Tab key.  This is
  59. '  what I came up with.  If there is a better way, such
  60. '  as through API calls, I would be interested in
  61. '  seeing it.  Since I couldn't beat it I joined it.
  62. 'Experianced Programmers:
  63. '  This documentation was written for beginner
  64. '  programmers.  If you are experianced skip the
  65. '  rest and just look at the code, it's not very
  66. '  difficult to figure out.
  67. 'Whats Needed:
  68. '  1.  A Form, MSFlexGrid, and Textbox.
  69. '  2.  The Form's KeyPreview property must be set
  70. '      to True.
  71. '  3.  The TabStop properties for all controls except
  72. '      for MSFlexGrid and Textbox should be set
  73. '      to false.
  74. '  4.  The MSFlexGrid TabIndex Property should be set
  75. '      to 0.
  76. '  5.  Navigation code should be put in the
  77. '      Textbox_GotFocus event.
  78. '  6.  The Textbox Visible property must be set to True.
  79. '      If you do not want to see it, place it off the
  80. '      visible portion of the form.
  81. 'How It Works:
  82. '  The program will start with focus set to the
  83. '  MSFlexGrid.
  84. '  When the tab key is pressed the focus
  85. '  is shifted to the Textbox.  This will in turn invoke
  86. '  the Textbox_GotFocus Event.  The Not ShiftPressed
  87. '  Navigation code is performed and focus is sent
  88. '  back to MSFlexGrid.
  89. '  When the Shift is pressed the Form_KeyDown Event is
  90. '  triggered, setting the ShiftPressed flag to true.
  91. '  Then when the Tab is pressed the focus is sent to
  92. '  the Textbox and the Textbox_Gotfocus Event is
  93. '  triggered.  The ShiftPressed code is performed and
  94. '  focus is sent back to MSFlexGrid.
  95. '  When the Shift is released the Form_KeyUp Event is
  96. '  triggered, setting the ShiftPressed flag to False.
  97. '  Ready for next set of keys to be pressed.
  98. Public ShiftPressed As Boolean
  99. Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
  100.     'If the Shift key is pressed, set Public variable
  101.     'ShiftPressed = True.  This flag set to true tells
  102.     'the program the shift key is being pressed.
  103.     Select Case Shift
  104.     Case 1  'Shift Key
  105.       ShiftPressed = True
  106.     Case Else
  107.       'Unload form when Escape is pressed
  108.       'Has nothing to do with navigation, I am just
  109.       'lazy.
  110.       If KeyCode = 27 Then Unload frmFlexNavigate
  111.     End Select
  112. End Sub
  113. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  114.     'When the Shift Key is up set the ShiftPressed
  115.     'variable equal to false.
  116.     If Shift = 0 Then ShiftPressed = False
  117. End Sub
  118. Private Sub Form_Load()
  119.     Dim i As Integer
  120.     'Setup MSFlexGrid and assign data.
  121.     With grd
  122.       .Rows = 1
  123.       .FormatString = "^Ascii Code|^Alpha Character"
  124.       .ColWidth(0) = .Width / 2 - 50
  125.       .ColWidth(1) = .Width / 2 - 50
  126.       For i = 65 To 68
  127.         .AddItem i & vbTab & Chr$(i)
  128.       Next i
  129.     End With
  130. End Sub
  131. Private Sub grd_Click()
  132. End Sub
  133. Private Sub tabSimm_GotFocus()
  134.     'This is where you put your desired navigation code
  135.     'for Shift Tab and Tab respectfully.
  136.     With grd
  137.       
  138.       'Shift is being pressed.
  139.       If ShiftPressed Then
  140.         If .Col = 1 Then
  141.           .Col = 0
  142.         ElseIf .Row = 1 Then
  143.           .Col = 1
  144.           .Row = .Rows - 1
  145.         Else
  146.           .Col = 1
  147.           .Row = .Row - 1
  148.         End If
  149.       End If
  150.       
  151.       'Shift is not being pressed.
  152.       If Not ShiftPressed Then
  153.         If .Col = 0 Then
  154.           .Col = 1
  155.         ElseIf .Row = .Rows - 1 Then
  156.           .Col = 0
  157.           .Row = 1
  158.         Else
  159.           .Col = 0
  160.           .Row = .Row + 1
  161.         End If
  162.       End If
  163.       
  164.       .SetFocus     'Set focus back to MSFlexGrid
  165.       
  166.     End With
  167.       
  168. End Sub
  169.